import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        List<String> abc = List.of("jij");
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        // while (in.hasNextInt()) { // 注意 while 处理多个 case
        //     int a = in.nextInt();
        //     int b = in.nextInt();
        //     System.out.println(a + b);
        // }
        // 草药总数
        int count = in.nextInt();
        // 投入草药上限
        int k = in.nextInt();
        // 目标丹药阴阳性(1 : 2)
        int x = in.nextInt();
        // 目标弹药属性值
        int y = in.nextInt();
        // caoyao[index][0] 草药价值
        // 【1】草药阴阳性
        // 【2】草药属性值
        int[][] caoyao = new int[count][3];
        int index = 0;
        while(in.hasNextInt()){
            caoyao[index][0] = in.nextInt();
            caoyao[index][1] = in.nextInt();
            caoyao[index][2] = in.nextInt();
            index++;
        }
        chengDan(k, x, y, caoyao, 0);
        System.out.println(minCaoyaoValue == Integer.MAX_VALUE ? "Cannot Make it" : minCaoyaoValue);
        caoyaoValue = 0;
        minCaoyaoValue = Integer.MAX_VALUE;
    }

    static int caoyaoValue = 0;
    static int minCaoyaoValue = Integer.MAX_VALUE;

    public static void chengDan(int k, int x, int y, int[][] caoyao, int index){
        if(k >= 0 && y == 0){
            // 丹成
            minCaoyaoValue = Math.min(caoyaoValue, minCaoyaoValue);
        }
        if(k <= 0 || y < 0|| index >= caoyao.length){
            // 废丹
            return;
        }
        for(int i = index; i < caoyao.length; i++){
            caoyaoValue += caoyao[i][0];
            // 先判断阴阳性
            int tempY = y;
            if(caoyao[i][1] == x){
                // 直接加
                tempY -= caoyao[i][2];
            }else{
                // 要减掉
                tempY += caoyao[i][2];
            }
            chengDan(k - 1, x, tempY, caoyao, i + 1);
            caoyaoValue -= caoyao[i][0];
        }
        return;
    }
}